package com.tensquare.user.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tensquare.user.mapper.TbUserMapper;
import com.tensquare.user.pojo.TbUser;
import com.tensquare.user.service.ITbUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用户 服务实现类
 * </p>
 *
 * @author XXX
 * @since 2022-10-29
 */
@Service
public class TbUserServiceImpl extends ServiceImpl<TbUserMapper, TbUser> implements ITbUserService {

    @Autowired
    private TbUserMapper userMapper;

    /**
     * 注册
     * @param userId
     * @return
     */
    @Override
    public int register(String userId) {
        TbUser tbUser=null;
        tbUser = userMapper.selectById(userId);
        if(tbUser!=null){
            return 0;
        }else {
            tbUser = new TbUser();
            tbUser.setId(userId);
            tbUser.setMobile(null);
            tbUser.setPassword("111111");
            tbUser.setNickname("张三");
            tbUser.setSex("男");
            tbUser.setBirthday(null);
            tbUser.setAvatar(null);
            tbUser.setEmail(null);
            tbUser.setRegdate(LocalDateTime.now());
            tbUser.setUpdatedate(null);
            tbUser.setLastdate(null);
            tbUser.setOnline(null);
            tbUser.setInterest(null);
            tbUser.setPersonality(null);
            tbUser.setFanscount(null);
            tbUser.setFollowcount(null);
            int insert = userMapper.insert(tbUser);
            return insert;
        }
        
            


       
    }

    /**
     * 根据用户id查询用户
     * @param userId
     * @return
     */
    @Override
    public TbUser selectByUserId(String userId) {
        return userMapper.selectById(userId);
    }
    
    /**
     * 登录
     * @param user
     * @return
     */
    @Override
    public TbUser login(TbUser user) {
        return userMapper.selectById(user.getId());
    }

    


}
